/**
 *  @file
 *  @brief   帽形1（HAT1）梁截面属性使用解析公式计算类
 *  @author  xiaochangjiang
 *  @date    2024.03.29
 *  @version v1.0
 *  @par Copyright(c):  ShenGong  Simulation corporation
 */

#include "Hat1SectionFormulaCalculator.h"
#include "DataStructure/Common/Real.h"

using SG::DataStructure::Common::Real;
using SG::DataStructure::FEM::PBARLData;
using SG::DataStructure::FEM::PBARData;
using SG::FEMSolver::Element::Hat1SectionFormulaCalculator;

void Hat1SectionFormulaCalculator::Compute
(
const SG::DataStructure::FEM::PBARLData& section,
_OUT SG::DataStructure::FEM::PBARData&   property,
_OUT SG::Algebra::Point&                 centroid
) const
{
    Real b1{section.m_dimension[0]};
    Real h{section.m_dimension[1]};
    Real b2{section.m_dimension[2]};
    Real t2{section.m_dimension[3]};
    Real t1{section.m_dimension[4]};

    /* Real fai1{t2 * (b1 - b2 + t2) * (b1 - b2 + t2) * (b1 - b2 + t2) / 6.0 + t2 * (b1 - b2 + t2) * (b1 + b2 - t2) * (b1 + b2 - t2) / 16.0 +
              t2 * (h - t1 - t2) * (b2 - t2) * (b2 - t2) * 0.5 + t2 * (b2 - t2) * (b2 - t2) * (b2 - t2) / 12.0 + t1 * b1 * b1 * b1 / 12.0};
    Real fai2{(b1 - b2 + t2) * (b1 + b2 - t2) * (h - t1 - t2) * 0.25 + (h - t1 - t2) * (h - t1 - t2) * (b2 - t2) * 0.5 +
              (b2 - t2) * (b2 - t2) * (b2 - t2) / 12.0 + (b1 - b2 + t2) * (b1 + b2 - t2) * (b2 - t2) / 6.0 +
              (h - t1 - t2) * (b2 - t2) * (b2 - t2) * 0.5 + b1 * b1 * (b2 - t2) / 12.0};
    Real fai3{t1 * t2 * fai2 / (2.0 * t1 * (h - t1 - t2) + (b2 - t2) * (t1 + t2))};
    Real fai{(b2 - t2) * (h - 0.5 * t1 - 0.5 * t2) * (t1 * (b1 - b2 + t2) * (b1 + b2 - t2) / 24.0 + t1 * b1 * b1 / 12.0 + fai3) +
             (b2 - t2) * (h - t1 - t2) * (t2 * (b1 - b2 + t2) * (b1 + b2 - t2) * 0.125 + t2 * (h - t1 - t2) * (b2 - t2) * 0.25 + fai3) +
             t1 * t2 * b1 * b1 * b1 / 12.0 - t1 * t2 * (b1 - b2 + t2) * (b1 + b2 - t2) * (b2 - t2) * 0.125 +
             t2 * t2 * b1 * b1 * b1 / 12.0 - t1 * t2 * b1 * b1 * (b2 - t2) / 12.0 +
             t1 * t2 * (b2 - t2) * (b1 - b2 + t2) * (b1 + b2 - t2) / 12.0 - t2 * t2 * (b2 - t2) * (b1 - b2 + t2) * (b1 + b2 - t2) * 0.125 -
             t2 * t2 * b1 * b1 * (b2 - t2) / 12.0 + t2 * t2 * (b2 - t2) * (b1 - b2 + t2) * (b1 + b2 - t2) / 12.0};
             */
    Real area{b1 * t1 + t2 * (b1 - b2) + 2.0 * t2 * (h - t1) + t2 * (b2 - 2.0 * t2)};
    Real yC{(b1 * t1 * 0.5 * t1 + t2 * (b1 - b2) * (t1 + 0.5 * t2) + t2 * (h * h - t1 * t1) + t2 * (b2 - 2.0 * t2) * (h - 0.5 * t2)) /
            area};
    property.m_id  = section.m_id;
    property.m_mId = section.m_mId;
    property.m_A   = area;
    // Real yS = fai / fai1 + 0.5 * t2;  // ToDo
    // Real zS = 0.0;
    // Real yC = yC;
    // Real zC = 0.0;
    property.m_I1  = b1 * t1 * t1 * t1 / 12.0 + b1 * t1 * (yC - 0.5 * t1) * (yC - 0.5 * t1) + (b1 - b2) * t2 * t2 * t2 / 12.0 +
                     (b1 - b2) * t2 * (yC - (t1 + 0.5 * t2)) * (yC - (t1 + 0.5 * t2)) + t2 * (h - t1) * (h - t1) * (h - t1) / 6.0 +
                     2.0 * t2 * (h - t1) * (yC - 0.5 * (h - t1) - t1) * (yC - 0.5 * (h - t1) - t1) +
                     (b2 - 2.0 * t2) * t2 * t2 * t2 / 12.0 + (b2 - 2.0 * t2) * t2 * (yC - (h - t2 / 2.0)) * (yC - (h - t2 / 2.0));
    property.m_I2  = t1 * b1 * b1 * b1 / 12.0 + t2 * (b1 - b2) * (b1 - b2) * (b1 - b2) / 48.0 +
                     t2 * (b1 - b2) * (b1 + b2) * (b1 + b2) / 16.0 + (h - t1) * t2 * t2 * t2 / 6.0 +
                     (h - t1) * t2 * (b2 - t2) * (b2 - t2) * 0.5 + 2.0 * t2 * (0.5 * b2 - t2) * (0.5 * b2 - t2) * (0.5 * b2 - t2) / 3.0;
    property.m_I12 = 0.0;
    property.m_J   = 4.0 * t1 * t2 * (b2 - t2) * (b2 - t2) * (h - 0.5 * t1 - 0.5 * t2) * (h - 0.5 * t1 - 0.5 * t2) /
                     ((b2 - t2) * (t1 + t2) + t1 * (2.0 * h - t1 - t2)) + (b1 - b2) * (t1 + t2) * (t1 + t2) * (t1 + t2) / 3.0;
    property.m_K1  = 2.0 * (h - t1) * t2 / area;
    property.m_K2  = 1.0 - property.m_K1;
    property.m_NSM = section.m_nsm;
    property.m_FE  = 0.0;
    property.SetStressPoints ({-yC,     -0.5 * b1,
                               -yC,      0.5 * b1,
                               -yC + h, -0.5 * b2,
                               -yC + h,  0.5 * b2});
    centroid.m_x = 0.0;
    centroid.m_y = 0.0;
    centroid.m_z = 0.0;
}